﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ViewModels
{
    /// <summary>
    /// 借阅视图模型
    /// </summary>
    public class BorrowVM
    {
        public Guid BorrowID { get; set; }
        public string BookID { get; set; }
        public Guid UserID { get; set; }//用户ID
        public DateTime BorrowDate { get; set; }
        public DateTime ReturnDate { get; set; }
        public bool isReturn { get; set; }
        public string isReturnString { get; set; }//是否归还的字符串
        public BookVM BookVM { get; set; }
        public UserVM UserVM { get; set; }
        public BorrowVM()
        {
            this.BorrowID 
                =this.UserID
                = Guid.NewGuid();
            this.BorrowDate 
                =this.ReturnDate
                = DateTime.Now;
            this.isReturn = false;
            if (this.isReturn)
                this.isReturnString = "已归还";
            else
                this.isReturnString = "未归还";
        }
        public BorrowVM(BorrowVM vm)
        {
            this.BorrowID = vm.BorrowID;
            this.BorrowDate = vm.BorrowDate;
            this.ReturnDate = vm.ReturnDate;
            this.isReturn = vm.isReturn;
            if (this.isReturn)
                this.isReturnString = "已归还";
            else
                this.isReturnString = "未归还";
            // 处理关联类BookVM、UserVM
            if (vm.BookVM != null)
            {
                this.BookID= vm.BookVM.BookID;
                this.BookVM.BookID = vm.BookVM.BookID;
                this.BookVM.BookName = vm.BookVM.BookName;
                this.BookVM.BookVersion = vm.BookVM.BookVersion;
                this.BookVM.BookVersion = vm.BookVM.BookVersion;
                this.BookVM.Author = vm.BookVM.Author;
                this.BookVM.ISBN = vm.BookVM.ISBN;
                this.BookVM.PublishDate = vm.BookVM.PublishDate;
                this.BookVM.Publisher = vm.BookVM.Publisher;
                this.BookVM.WordCount = vm.BookVM.WordCount;
                this.BookVM.PageCount = vm.BookVM.PageCount;
                this.BookVM.Price = vm.BookVM.Price;
            }
            if (UserVM != null)
            {
                this.UserID = vm.UserVM.UserID;
                this.UserVM.UserID = vm.UserVM.UserID;
                this.UserVM.UserName = vm.UserVM.UserName;
                this.UserVM.UserPwd = vm.UserVM.UserPwd;
                this.UserVM.StuNo = vm.UserVM.StuNo;
                this.UserVM.Name = vm.UserVM.Name;
                this.UserVM.Gender = vm.UserVM.Gender;
                if (this.UserVM.Gender)
                    this.UserVM.GenderString = "男";
                else
                    this.UserVM.GenderString = "女";
                this.UserVM.IDNumber = vm.UserVM.IDNumber;
                this.UserVM.CreateDate = vm.UserVM.CreateDate;
                this.UserVM.Email = vm.UserVM.Email;
                this.UserVM.Mobile = vm.UserVM.Mobile;
                this.UserVM.Address = vm.UserVM.Address;
                this.UserVM.URL = vm.UserVM.URL;
            }
        }
    }
}
